<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <link href="assets/vakata-jstree-7a976d1/dist/themes/default/style.min.css" rel="stylesheet"/>
    <link href="assets/DataTables-1.10.11/media/css/dataTables.bootstrap.min.css" rel="stylesheet"/>
    <!--<link href="assets/layer-v2.2/layer/skin/layer.css" rel="stylesheet"/>-->
    <link href="assets/images/log.ico" rel="shortcut icon">
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <style type="text/css">
        .mapBall{
            width:20px;
            height:20px;
            background: red;
            border-radius: 50%;
            position: absolute;
        }
        .table>tbody>tr>td{
            text-align:center;
            line-height: 15px;
            font-size: 15px;
        }
        .table>thead:first-child>tr:first-child>th{
            text-align:center;
        }
    </style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <!--顶部导航栏开始-->
    <header id="top_header" class="main-header">
        <!-- Logo -->
        <a href="main_page.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>T</b>pson</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!--<img src="assets/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i>
                        <span>主页</span>
                    </a>
                </li>

                <li class="treeview">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview active">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-red"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-yellow"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper">
        <section class="content-header" id="page_header">
            <h1>
                <b>监测点配置</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#"><i class="fa fa-chain-broken"></i> 监测点配置</a> </li>
                <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o"></i> 监测点录入</a></li>
            </ol>
        </section>
        <section class="invoice">
           <div class="row">
               <div class="col-md-12">
                   <div class="nav-tabs-custom" style="margin-bottom: 0px">
                       <ul class="nav nav-tabs">
                           <li class="active"><a href="#tab_2" data-toggle="tab">监测点查询与删除</a> </li>
                           <li><a href="#tab_1" data-toggle="tab">监测点录入</a> </li>
                           <!--<li id="changeData"><a href="#tab_0" data-toggle="tab" disabled="disabled">监测点录入</a></li>-->
                       </ul>
                       <div class="tab-content">
                           <!--查询界面-->
                           <div class="tab-pane active" id="tab_2">
                               <div class="row">
                                   <div class="box box-warning " style="margin-bottom: 0px">
                                       <div class="box-header">
                                           <h4 class="box-title"><b>监测点列表</b></h4>
                                       </div>
                                       <div class="box-body">
                                           <table id="del_data_table" class="table table-bordered table-striped">
                                               <thead>
                                               <tr>
                                                   <th>ID</th>
                                                   <th>监测点名称</th>
                                                   <th>所属用户信息传输装置</th>
                                                   <th>地理位置信息</th>
                                                   <th>传感器类型</th>
                                                   <th>操作</th>
                                               </tr>
                                               </thead>
                                               <tbody id="del_data_table_tbody">

                                               </tbody>
                                           </table>
                                       </div>
                                   </div>
                               </div>
                           </div>
                           <!--录入界面-->
                           <div class="tab-pane " id="tab_1">
                                  <div class="row">
                                      <div class="box box-info">
                                          <div class="box-header">
                                              <h4 class="box-title"><b>1 选择传感器类别</b></h4>
                                          </div>
                                          <div class="box-body" id="sensor_div">
                                              <div class="col-md-4">
                                                  <div class="form-group">
                                                      <label>一级</label>
                                                      <select id="sensor_select_level1"  class="form-control select2 sensor_level_1" style="width: 100%;">
                                                      </select>
                                                  </div><!-- /.form-group -->
                                              </div>
                                              <div class="col-md-4">
                                                  <div class="form-group">
                                                      <label>二级</label>
                                                      <select id="sensor_select_level2" class="form-control select2 sensor_level_2" style="width: 100%;">
                                                      </select>
                                                  </div><!-- /.form-group -->
                                              </div>
                                              <div class="col-md-4 ">
                                                  <div class="form-group">
                                                      <label>三级</label>
                                                      <select id="sensor_select_level3" class="form-control select2 sensor_level_3" style="width: 100%;">
                                                      </select>
                                                  </div>
                                              </div>
                                          </div>
                                      </div>
                                  </div>

                                  <div class="row">
                                      <div class="box box-warning">
                                          <div class="box-header">
                                              <h4 class="box-title"><b>2 选择地图</b></h4>
                                          </div>
                                          <div id="loction_input_div" class="box-body">
                                              <div class="col-md-4">
                                                  <div class="form-group">
                                                      <label>区域</label>
                                                      <select id="area_select"  class="form-control select2 input_area" style="width: 100%;">

                                                      </select>
                                                  </div>
                                              </div>
                                              <div class="col-md-4">
                                                  <div class="form-group">
                                                      <label>建筑物</label>
                                                      <select id="build_select" class="form-control select2 input_build" style="width: 100%;">

                                                      </select>
                                                  </div>
                                              </div>
                                              <div class="col-md-4 ">
                                                  <div class="form-group">
                                                      <label>楼层</label>
                                                      <select id="floor_select" class="form-control select2 input_floor" style="width: 100%;">

                                                      </select>
                                                  </div><!-- /.form-group -->
                                              </div>
                                          </div>
                                      </div>
                                  </div>

                                  <div class="row">
                                      <div class="box box-success">
                                          <div class="box-header">
                                              <h4 class="box-title"><b>3 录入传感器信息</b></h4>
                                          </div>
                                          <div class="box-body">
                                              <div class="col-md-4 ">
                                                  <div class="form-group">
                                                      <label>名称</label>
                                                      <input id="sensor_name_input" type="text" class="form-control" placeholder="请输入名称">
                                                  </div>
                                              </div>
                                              <div class="col-md-2 " id="eq_select_div">
                                                  <div class="form-group">
                                                      <label>所属用户信息传输装置</label>
                                                      <select id="router_select" class="form-control select2 eq_select">
                                                      </select>
                                                  </div>
                                              </div>
                                              <div class="col-md-2 ">
                                                  <div class="form-group">
                                                      <label>报警回路号</label>
                                                      <input id="alert_code_input" type="text" class="form-control" placeholder="请输入报警回路号">
                                                  </div>
                                              </div>
                                              <div class="col-md-4">
                                                  <div class="col-sm-4 ">
                                                      <div class="form-group">
                                                          <label>坐标X</label>
                                                          <input id="map_pos_x" type="text" class="form-control" disabled>
                                                      </div>
                                                  </div>
                                                  <div class="col-sm-4 ">
                                                      <div class="form-group">
                                                          <label>坐标Y</label>
                                                          <input id="map_pos_y" type="text" class="form-control" disabled>
                                                      </div>
                                                  </div>
                                                  <div class="col-sm-4">
                                                      <button id="saveMonitorBtn" type="button" class="btn btn-success btn-block pull-right"  style="margin-top: 22px"><i class="fa fa-upload"></i> 提交</button>
                                                  </div>
                                              </div>
                                          </div>
                                      </div>
                                  </div>
                                  <div class="row">
                                      <div class="box box-danger">
                                          <div class="box-header">
                                              <h4 class="box-title"><b>4 标注坐标点</b></h4>
                                          </div>
                                          <div class="box-body">
                                              <div  id="monitor_map_div" style="position: relative; margin-top: 10px">

                                              </div>
                                          </div>
                                      </div>
                                  </div>
                              </div>
                       </div>
                   </div>
               </div>
           </div>

        </section>
        <div class="clearfix"></div>
    </div>
    <!--内容区结束-->
    <!--页脚开始-->
    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b>  3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
    <!--页脚结束-->
</div>
<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/fastclick/fastclick.min.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<script src="assets/vakata-jstree-7a976d1/dist/jstree.min.js"></script>
<script src="assets/DataTables-1.10.11/media/js/jquery.dataTables.min.js"></script>
<script src="assets/DataTables-1.10.11/media/js/dataTables.bootstrap.min.js"></script>
<script src="assets/cxSelect-master/js/jquery.cxselect.min.js"></script>
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>
<script src="js/alert_check.js"></script>
<script>
    var loctionData;    //地理点信息
    var monitorTable;
    var pageIndex = 1;
    var server;
    var sensorData = [];
    var eqData = [];
    var mapData = [];
    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        loadLoctionData();
        getSensorType();
        getEQ();
        initMonitorTable();
        ReadTable();
        window.onload = checkAlert(server);
    });
    //获取用户信息传输装置信息
    function getEQ() {
        $.ajax({
            url:server + "/xk/xkDevice/getAll",
            success:function (data) {
                eqData = JSON.parse(data);
                $('#eq_select_div').cxSelect({
                    selects: ['eq_select'],
                    jsonName: 'name',
                    jsonValue: 'id',
                    data:eqData.data
                });
            }
        });
    }
    //获取地理信息数据
    function loadLoctionData() {
        $.ajax({
            url: server + "/xk/xkGeoLocation/getTree",
            async:false,
            type:"GET",
            success:function (data_in) {
                var jsonObj = JSON.parse(data_in);
                mapData = [];     //地图信息
                var data = [];     //地理信息
                for(var i  in jsonObj.data){
                    var level1 = jsonObj.data;
                    var level1Obj = {
                        text:level1[i].name,
                        id:level1[i].id,
                    };
                    if(level1[i].children != null)
                    {
                        var level2 = level1[i].children;
                        var level2Arr = [];
                        for(var j in level2){
                            var level2Obj = {
                                text: level2[j].name,
                                id: level2[j].id,
                            };
                            if(level2[j].children != null)
                            {
                                var level3 = level2[j].children;
                                var level3Arr = [];
                                for(var k in level3){
                                    var level3Obj = {
                                        text: level3[k].name,
                                        id: level3[k].id,
                                    };
                                    level3Arr.push(level3Obj);
                                    var floorObj = {
                                        id: level3[k].id,
                                        picture: level3[k].picture
                                    };
                                    mapData.push(floorObj);
                                }
                                level2Obj .children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    data.push(level1Obj);
                }
                loctionData = data;
            }
        });
        $('#loction_input_div').cxSelect({
            selects: ['input_area', 'input_build', 'input_floor'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:loctionData
        });
        $('#loction_delete_div').cxSelect({
            selects: ['delete_area', 'delete_build', 'delete_floor'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:loctionData
        });
    }
    //获取传感器列表
    function getSensorType() {
        $.ajax({
            url:server + "/xk/xkSensor/getTree",
            async:false,
            type:"GET",
            success:function (data_in) {
                var jsonObj = JSON.parse(data_in);
                sensorData = [];
                for(var i in jsonObj.data){
                    var level1Data = jsonObj.data;
                    var level1Obj = {
                        //id,parentid,菜单等级
                        id: level1Data[i].id,
                        text: level1Data[i].name,
                    };
                    if(level1Data[i].children != undefined){
                        var level2Data = level1Data[i].children;
                        var level2Arr = [];
                        for(var j in level2Data){
                            var level2Obj = {
                                text: level2Data[j].name,
                                id: level2Data[j].id,
                            };
                            if(level2Data[j].children != undefined)
                            {
                                var level3Data = level2Data[j].children;
                                var level3Arr = [];
                                for(var k in level3Data){
                                    var level3Obj = {
                                        text: level3Data[k].name,
                                        id: level3Data[k].id,
                                    };
                                    level3Arr.push(level3Obj);
                                }
                                level2Obj.children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    sensorData.push(level1Obj);
                }
            }
        });
        $('#sensor_div').cxSelect({
            selects: ['sensor_level_1', 'sensor_level_2','sensor_level_3'],
            jsonName: 'text',
            jsonValue: 'id',
            jsonSub: 'children',
            data:sensorData
        });
    }
//  *************************************查询与删除*************************************
    function ReadTable() {
        $.ajax({
            url:server+"/xk/xkMonitor/getAll" ,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                console.log(json);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    var monitorDataShow = [];
                    for(var i in json.data){
                        var datas = json.data;
                        var obj = {
                            id: datas[i].id,
                            name:datas[i].monitor_name,
                            device_name:datas[i].device_name,
                            location:datas[i].geo_1+'_'+datas[i].geo_2+'_'+datas[i].geo_3,
                            sensor_name:datas[i].sensor_name,
                        };
                        monitorDataShow.push(obj);
                    }
                    monitorTable.clear().draw();
                    monitorTable.rows.add(monitorDataShow).draw();
                }
                layer.close(index);
            }
        });
    }
    function initMonitorTable() {
        monitorTable = $('#del_data_table').DataTable({
            paging: true,
            columns:[
                {data: "id"},
                {data: "name"},
                {data: "device_name"},
                {data: "location"},
                {data: "sensor_name"},
                {data: null,"width":"200px"}
            ],
            columnDefs:[{
                targets:5,
                render: function (data, type, row, meta) {
                  return '<div class="col-sm-5" style="margin-right: 10px"><a type="button"  data-toggle="tab" class="btn btn-warning fa fa-edit" onclick=editRecord('+row.id+')>编辑</a></div>' +
                          '<div class="col-sm-5"><button type="button" class="btn btn-danger fa fa-remove" onclick=delMonitor('+row.id+')>删除</button></div>';
                }
            },
                {   'orderable': false,
                    'targets': 5
                },],

            language:{
                "sProcessing":   "处理中...",
                "sLengthMenu":   "显示 _MENU_ 项结果",
                "sZeroRecords":  "没有匹配结果",
                "sInfo":         "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty":    "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix":  "",
                "sSearch":       "搜索:",
                "sUrl":          "",
                "sEmptyTable":     "表中数据为空。",
                "sLoadingRecords": "载入中...",
                "sInfoThousands":  ",",
                "oPaginate": {
                    "sFirst":    "首页",
                    "sPrevious": "上页",
                    "sNext":     "下页",
                    "sLast":     "末页"
                },
                "oAria": {
                    "sSortAscending":  ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        });
    };
    //删除监测点
    function delMonitor(id) {
        var index = layer.load(0, {shade: false});
        $.ajax({
            url:server +'/xk/xkMonitor/delete?id=' + id,
            success:function (data) {
                layer.alert('数据删除成功！',{
                    closeBtn: 0
                });
                ReadTable();
                layer.close(index);
            }

        });
    }
//************************************************录入界面**************************************************************
    function mapOnClick(e){
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#map_pos_x').val(x.toFixed(10));
        $('#map_pos_y').val(y.toFixed(10));
    }
    function input_setRedBall(r) {
        var radius = r;
        var w = radius * 2;
        var h = radius * 2;
        var x, y, offset;
        return function (e) {
            offset = $(this).offset();
            x = e.pageX - offset.left;
            y = e.pageY - offset.top;
            if($('#mapPoint') != null) $('#mapPoint').remove();
            $('<span id="mapPoint" class="mapBall"></span>').css({
                left: x - radius,
                top: y - radius,
                width: w,
                height: h
            }).appendTo(this);
        }
    }
    //图片热点标注
    $('#monitor_map_div').on('click', input_setRedBall(10));
    //加载楼层图片
    $('#floor_select').change(function () {
        var ID = $('#floor_select').val();
        for(var i in mapData){
            if(mapData[i].id == ID){
                var picture = mapData[i].picture;
                $('#monitor_map_div').empty();
                if(picture != ""){
                    $('#monitor_map_div').append(
                            '<img id="monitor_map" src="'+server+'/xk/xkGeoLocation/mapDownload?id='+ID+'"  class="col-xs-12" style="margin:0 auto;padding:0; width:100%" onclick="mapOnClick(event)"/>'
                    );
                }
                else{
                    layer.alert('服务器未存储地图数据！请先录入！',{
                        closeBtn: 0
                    });
                }
                break;
            }
        }
    });
    //提交监测点
    $('#saveMonitorBtn').click(function () {
        var sensor_level_3 = $("#sensor_select_level3").val();
        var geo_level_1 = $("#area_select").val();
        var geo_level_2 = $("#build_select").val();
        var geo_level_3 = $("#floor_select").val();
        var device_id =$("#router_select").val();
        var name = $('#sensor_name_input').val();
        var alarm_no = $('#alert_code_input').val();
        var pos_x = $('#map_pos_x').val();
        var pos_y = $('#map_pos_y').val();
        var formDatas = new FormData();
        formDatas.append("sensor_id",sensor_level_3);
        formDatas.append("geo_level_1_id",geo_level_1);
        formDatas.append("geo_level_2_id",geo_level_2);
        formDatas.append("geo_level_3_id",geo_level_3);
        formDatas.append("device_id",device_id);
        formDatas.append("name",name);
        formDatas.append("code",alarm_no);
        formDatas.append("pos_x",pos_x);
        formDatas.append("pos_y",pos_y);

        if(name&&alarm_no&&device_id&&sensor_level_3&&geo_level_3){
            $.ajax({
                type:"post",
                contentType : false,
                processData:false,
                url:server+'/xk/xkMonitor/add',
                data:formDatas,
                success:function (data) {
                    if(JSON.parse(data).code == 0){
                        layer.alert('数据录入成功！',{
                            closeBtn: 0
                        });
                        ReadTable();
                    }
                    else{
                        layer.alert('操作失败：' + data,{
                            closeBtn: 0
                        });
                    }
                }
            });
        }else {
            layer.alert('请输入完整的筛选信息！',{
                closeBtn: 0
            });
        }
    });
//************************************************修改界面*****************************************************************
    function editRecord(id) {
        var sensorLevel1;
        var sensorLevel2;
        var sensorLevel3;
        var name;
        var deviceName;
        var deviceId;
        var geoLevel1;
        var geoLevel2;
        var geoLevel3;
        var posX;
        var posY;
        var alarmNo;
        layer.open({
            type: 1,
            title:'监测点编辑',
            skin:'layui-layer-lan',
            area:['1000px', 'auto'],
            maxmin:true,
            maxHeight:'1000px',
            scrollbar: false,
            content:'<div class="tab-pane" id="tab_0" style="width:98%">'
            +'  <div class="row">'
            +'      <div class="col-sm-12">'
            +'          <div class="box box-warning">'
            +'              <div class="box-header">'
            +'                  <h4 class="box-title"><b>2 修改监测点</b></h4>'
            +'              </div>'
            +'              <div class="box-body" id="change_monitor_box_body">'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.1 传感器类别</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div id="monitor_sensor_change_div">'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>一级</label>'
            +'                                  <select id="monitor_change_sensor1_select" class="form-control select2 monitor_change_sensor1_select_class" value></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>二级</label>'
            +'                                  <select id="monitor_change_sensor2_select" class="form-control select2 monitor_change_sensor2_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                          <div class="col-sm-3">'
            +'                              <div class="form-group">'
            +'                                  <label>三级</label>'
            +'                                  <select id="monitor_change_sensor3_select" class="form-control select2 monitor_change_sensor3_select_class"></select>'
            +'                              </div>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3" id="monitor_change_router_div">'
            +'                          <div class="form-group">'
            +'                              <label>用户信息传输装置</label>'
            +'                              <select id="monitor_change_router_select" class="form-control select2 monitor_change_router_select_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.2 监测点地理位置</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="" id="monitor_change_location_div">'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>区域</label>'
            +'                              <select id="monitor_change_area_select2" class="form-control select2 monitor_change_area_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>建筑物</label>'
            +'                              <select id="monitor_change_build_select2" class="form-control select2 monitor_change_build_select2_class"></select>'
            +'                          </div>'
            +'                          <div class="form-group col-sm-3">'
            +'                              <label>楼层</label>'
            +'                              <select id="monitor_change_floor_select2" class="form-control select2 monitor_change_floor_select2_class"></select>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">2.3 设定新监测点名称与坐标点</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="col-sm-3">'
            +'                          <div class="form-group">'
            +'                              <label>监测点名称</label>'
            +'                              <input id="monitor_change_name_input" type="text" class="form-control" placeholder="请输入监测点名称">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-3 ">'
            +'                          <div class="form-group">'
            +'                              <label>报警回路号</label>'
            +'                              <input id="monitor_change_alert_number_input" type="text" class="form-control">'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2">'
            +'                          <div class="form-group">'
            +'                              <label>监测点X坐标</label>'
            +'                              <input id="monitor_change_pos_x_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                      <div class="col-sm-2 ">'
            +'                          <div class="form-group">'
            +'                              <label>监测点Y坐标</label>'
            +'                              <input id="monitor_change_pos_y_input" type="text" class="form-control" disabled>'
            +'                          </div>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div class="box-header">'
            +'                          <h4 class="box-title">地图点选</h4>'
            +'                      </div>'
            +'                  </div>'
            +'                  <div class="row">'
            +'                      <div id="monitor_change_map_div" >'
            +'                      </div>'
            +'                  </div>'
            +'              </div>'
            +'          </div>'
            +'      </div>'
            +'  </div>'
            +'</div>'
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                var sensor_id = $('#monitor_change_sensor3_select').val();
                var geo_level_1_id = $('#monitor_change_area_select2').val();
                var geo_level_2_id = $('#monitor_change_build_select2').val();
                var geo_level_3_id = $('#monitor_change_floor_select2').val();
                var device_id = $('#monitor_change_router_select').val();
                var name = $('#monitor_change_name_input').val();
                var code = $('#monitor_change_alert_number_input').val();
                var pos_x = $('#monitor_change_pos_x_input').val();
                var pos_y = $('#monitor_change_pos_y_input').val();
                var formDatas = new FormData();
                formDatas.append("id",id);
                formDatas.append("sensor_id",sensor_id);
                formDatas.append("geo_level_1_id",geo_level_1_id);
                formDatas.append("geo_level_2_id",geo_level_2_id);
                formDatas.append("geo_level_3_id",geo_level_3_id);
                formDatas.append("device_id",device_id);
                formDatas.append("name",name);
                formDatas.append("code",code);
                formDatas.append("pos_x",pos_x);
                formDatas.append("pos_y",pos_y);
                $.ajax({
                    type:"post",
                    contentType : false,
                    processData:false,
                    url: server + "/xk/xkMonitor/update" ,
                    data:formDatas,
                    success:function () {
                        layer.alert('数据修改成功！',{
                            closeBtn: 0
                        });
                        ReadTable();
                    }
                });
            },
            btn2:function (index,layero) {
            },
            success: function(){
                getMonitor(id);
                getEQ(deviceId);
                loadLoctionData(geoLevel1,geoLevel2,geoLevel3);
                getSensorType(sensorLevel1,sensorLevel2,sensorLevel3);
                $("#monitor_change_name_input").val(name);
                $("#monitor_change_alert_number_input").val(alarmNo);
                $("#monitor_change_pos_x_input").val(posX);
                $("#monitor_change_pos_y_input").val(posY);
                $('#monitor_change_map_div').empty();
                var imgs = "";
                imgs = '<img id="show_map" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="'+server+'/xk/xkGeoLocation/mapDownload?id='+geoLevel3+'" onclick="mapOnClick2(event)" />';
                $('#monitor_change_map_div').append(imgs);
                setTimeout("initBall()",1000);
                $("#monitor_change_floor_select2").change(function(){
                    var mapId = $('#monitor_change_floor_select2').val();
                    $('#monitor_change_map_div').empty();
                    var imgs = "";
                    imgs = '<img id="show_map2" style="width: 100%;height: 100%"  class="ip_tooltipImg"  src="'+server+'/xk/xkGeoLocation/mapDownload?id='+mapId+'" onclick="mapOnClick2(event)" />';
                    $('#monitor_change_map_div').append(imgs);
                    setTimeout("initBall()",1000);
                })
            }
        });
        //获取监测点信息
        function getMonitor(id){
            $.ajax({
                url:server + "/xk/xkMonitor/get?id=" + id,
                async:false,
                success:function(data_in){
                    var jsonobj = JSON.parse(data_in).data;
                    console.log(jsonobj);
                    name = jsonobj.name;
                    deviceId = jsonobj.device_id;
                    geoLevel1 = jsonobj.geo_level_1_id;
                    geoLevel2 = jsonobj.geo_level_2_id;
                    geoLevel3 = jsonobj.geo_level_3_id;
                    sensorLevel1 = jsonobj.sensor_level_1_id;
                    sensorLevel2 = jsonobj.sensor_level_2_id;
                    sensorLevel3 = jsonobj.sensor_level_3_id;
                    posX = jsonobj.pos_x;
                    posY =jsonobj.pos_y;
                    alarmNo = jsonobj.description;
                }
            })
        }
        //获取用户信息传输装置信息
        function getEQ(deviceId) {
            $.ajax({
                url:server + "/xk/xkDevice/getAll",
                async:false,
                success:function (data) {
                    eqData = JSON.parse(data);
                    $('#monitor_change_router_div').cxSelect({
                        selects: ['monitor_change_router_select_class'],
                        jsonName: 'name',
                        jsonValue: 'id',
                        data:eqData.data
                    });
                    var cmb = document.getElementById("monitor_change_router_select");
                    option_items_select(cmb,deviceId);
                }
            });
        }
        //获取地理信息数据
        function loadLoctionData(geoLevel1,geoLevel2,geoLevel3) {
            $.ajax({
                url: server + "/xk/xkGeoLocation/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = JSON.parse(data_in);
                    mapData = [];     //地图信息
                    var data = [];     //地理信息
                    for(var i  in jsonObj.data){
                        var level1 = jsonObj.data;
                        var level1Obj = {
                            text:level1[i].name,
                            id:level1[i].id,
                        };
                        if(level1[i].children != null)
                        {
                            var level2 = level1[i].children;
                            var level2Arr = [];
                            for(var j in level2){
                                var level2Obj = {
                                    text: level2[j].name,
                                    id: level2[j].id,
                                };
                                if(level2[j].children != null)
                                {
                                    var level3 = level2[j].children;
                                    var level3Arr = [];
                                    for(var k in level3){
                                        var level3Obj = {
                                            text: level3[k].name,
                                            id: level3[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                        var floorObj = {
                                            id: level3[k].id,
                                            picture: level3[k].picture
                                        };
                                        mapData.push(floorObj);
                                    }
                                    level2Obj .children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        data.push(level1Obj);
                    }
                    loctionData = data;
                }
            });
            $('#monitor_change_location_div').cxSelect({
                selects: ['monitor_change_area_select2_class', 'monitor_change_build_select2_class', 'monitor_change_floor_select2_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:true,
                jsonSub: 'children',
                data:loctionData
            });
            var cmb1 = document.getElementById("monitor_change_area_select2");
            option_items_select(cmb1,geoLevel1);
            var i,j;
            for(i=0; i<loctionData.length;i++){
                if(loctionData[i].id == geoLevel1){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_build_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_build_select2");
                    option_items_select(cmb2,geoLevel2);
                    break;
                }
            }
            for(j = 0;j<loctionData[i].children.length;j++){
                if(loctionData[i].children[j].id == geoLevel2){
                    $('#monitor_change_location_div').cxSelect({
                        selects: ['monitor_change_floor_select2_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:loctionData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_floor_select2");
                    option_items_select(cmb3,geoLevel3);
                    break;
                }
            }
        }
        //获取传感器列表
        function getSensorType(sensorLevel1,sensorLevel2,sensorLevel3) {
            $.ajax({
                url:server + "/xk/xkSensor/getTree",
                async:false,
                type:"GET",
                success:function (data_in) {
                    var jsonObj = JSON.parse(data_in);
                    sensorData = [];
                    for(var i in jsonObj.data){
                        var level1Data = jsonObj.data;
                        var level1Obj = {
                            //id,parentid,菜单等级
                            id: level1Data[i].id,
                            text: level1Data[i].name,
                        };
                        if(level1Data[i].children != undefined){
                            var level2Data = level1Data[i].children;
                            var level2Arr = [];
                            for(var j in level2Data){
                                var level2Obj = {
                                    text: level2Data[j].name,
                                    id: level2Data[j].id,
                                };
                                if(level2Data[j].children != undefined)
                                {
                                    var level3Data = level2Data[j].children;
                                    var level3Arr = [];
                                    for(var k in level3Data){
                                        var level3Obj = {
                                            text: level3Data[k].name,
                                            id: level3Data[k].id,
                                        };
                                        level3Arr.push(level3Obj);
                                    }
                                    level2Obj.children = level3Arr;
                                }
                                level2Arr.push(level2Obj);
                            }
                            level1Obj.children = level2Arr;
                        }
                        sensorData.push(level1Obj);
                    }
                }
            });
            $('#monitor_sensor_change_div').cxSelect({
                selects: ['monitor_change_sensor1_select_class', 'monitor_change_sensor2_select_class','monitor_change_sensor3_select_class'],
                jsonName: 'text',
                jsonValue: 'id',
                required:true,
                jsonSub: 'children',
                data:sensorData
            });
            var cmb1 = document.getElementById("monitor_change_sensor1_select");
            option_items_select(cmb1,sensorLevel1);
            var i,j;
            for(i=0; i<sensorData.length;i++){
                if(sensorData[i].id == sensorLevel1){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor2_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children,
                    });
                    var cmb2 = document.getElementById("monitor_change_sensor2_select");
                    option_items_select(cmb2,sensorLevel2);
                    break;
                }
            }
            for(j = 0;j<sensorData[i].children.length;j++){
                if(sensorData[i].children[j].id == sensorLevel2){
                    $('#monitor_sensor_change_div').cxSelect({
                        selects: ['monitor_change_sensor3_select_class'],
                        jsonName: 'text',
                        jsonValue: 'id',
                        nodata: 'none',
                        jsonSub: 'children',
                        data:sensorData[i].children[j].children,
                    });
                    var cmb3 = document.getElementById("monitor_change_sensor3_select");
                    option_items_select(cmb3,sensorLevel3);
                    break;
                }
            }
        }
        //设置下拉框默认值
        function option_items_select(cmb,value){
            for(var i = 0;i<cmb.options.length;i++){
                if(cmb.options[i].value == value){
                    cmb.selectedIndex = i;
                    return;
                }
            }
        }
    }
    function initBall(){
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var x = $('#monitor_change_pos_x_input').val();
        var y = $('#monitor_change_pos_y_input').val();
        posSetBall2(w,h,x,y);
    }
    //获取图片坐标值
    function mapOnClick2(e){
        console.log("Test");
        e = e || window.event;
        var imgId ='#'+ $(e.target).attr('id');
        var currentWidth = $(imgId).width();
        var currentHeight = $(imgId).height();
        var offsetX = e.pageX - $(imgId).offset().left;
        var offsetY = e.pageY - $(imgId).offset().top;
        var x = offsetX / currentWidth;
        var y = offsetY / currentHeight;
        $('#monitor_change_pos_x_input').val(x.toFixed(10));
        $('#monitor_change_pos_y_input').val(y.toFixed(10));
        var w = $('#monitor_change_map_div').width();
        var h = $('#monitor_change_map_div').height();
        var spans = document.getElementsByClassName("mapBall");
        if(spans.length>0){
            $("#monitor_change_map_div .mapBall").remove();
        }
        posSetBall2(w,h,x,y)
    }
    //画坐标点
    function posSetBall2(w,h,x,y) {
        var curX = w * x;
        var curY = h * y;
        $('<span class="mapBall">').css({
            width: 20,
            height: 20,
            left: curX + $('#monitor_change_map_div ').position().left-10,
            top: curY + $('#monitor_change_map_div ').position().top-10
        }).appendTo($('#monitor_change_map_div '));
    }
</script>
</body>
</html>